package com.wonder.common.common;



import lombok.Data;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.wonder.common.constants.Constants;
import org.web3j.abi.datatypes.primitive.Long;

import java.util.ArrayList;
import java.util.List;

@Data
public class CommonPage<T> {
    private long current_page = (long) Constants.DEFAULT_PAGE;
    private long per_page = (long) Constants.DEFAULT_LIMIT;
    private long last_Page = 0L;
    private long total = 0L ;
    private List<T> data = new ArrayList<>();
    
    
    
    /**
     * 将IPage分页后的list转为分页信息
     */
    public static <T> CommonPage<T> restPage(IPage<T> page) {
        CommonPage<T> result = new CommonPage<T>();
    
        result.setLast_Page(page.getPages());
        result.setCurrent_page(page.getCurrent());
        result.setPer_page(page.getSize());
        result.setTotal(page.getTotal());
        result.setData(page.getRecords());
        return result;
    }


}
